var isEmpty = function(obj) {
    if (typeof obj == "undefined" || obj == null || obj == "") {
        return true;
    } else {
        return false;
    }
}

var checkLoginState = function() {
    var token = uni.getStorageSync('AppToken');
    if (token) {
        return true
    } else {
        return false
    }
}

var getDictLabelName = function(key, dictValue) {
    if (dictValue == null) {
        return "";
    }
    var dicts = uni.getStorageSync('dicts');
    dicts = JSON.parse(dicts);
    var dict = dicts[key]
    var name = "";
    dict.forEach(function(item, index, array) {
        if (dictValue.toString() == item.dictValue.toString()) {
            name = item.dictLabel
        }
    });
    return name;
}


var photosToArr = function(photoUrl) {
    var photos = [];
    if (photoUrl != null && photoUrl != '') {
        photos = photoUrl.split(',');
    }
    console.log(photos)
    return photos
}

var dateFormat = function dateFormat(fmt, date) {
    let ret;
    const opt = {
        "Y+": date.getFullYear().toString(), // 年
        "m+": (date.getMonth() + 1).toString(), // 月
        "d+": date.getDate().toString(), // 日
        "H+": date.getHours().toString(), // 时
        "M+": date.getMinutes().toString(), // 分
        "S+": date.getSeconds().toString() // 秒
        // 有其他格式化字符需求可以继续添加，必须转化成字符串
    };
    for (let k in opt) {
        ret = new RegExp("(" + k + ")").exec(fmt);
        if (ret) {
            fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
        };
    };
    return fmt;
}


var hasPermi = function(key) {
    var perms = uni.getStorageSync('perms');
    var permList = JSON.parse(perms);
    if (permList[0] == "*:*:*") {
        return true;
    }
    var flag = false;
    permList.forEach(function(item, index, array) {
        if (key == item) {
            flag = true;
        }
    });
    return flag;
}
module.exports = {
    isEmpty: isEmpty,
    checkLoginState: checkLoginState,
    getDictLabelName: getDictLabelName,
    photosToArr: photosToArr,
    dateFormat: dateFormat,
    hasPermi: hasPermi

};